<?php

namespace App\Http\Validate\OpenShop\ShopCheckAccept;

use App\Enums\OpenShop\InvestmentPromotion\MainProcessEnum;
use App\Enums\OpenShop\InvestmentPromotion\SignOrderEnum;
use App\Http\Validate\AbstractBaseValidate;
use Illuminate\Support\MessageBag;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

/**
 * [ 订单业务验证 ] - 校验规则
 *
 * @OpenShopUserContractValidate
 * @package App\Http\Controllers
 * @date 2022/03/01 02:35:56
 * @author GreenLeaf <786407418@qq.com>
 */
class ShopCheckAcceptValidate extends AbstractBaseValidate
{
    public function registerValidateRules(): void
    {
        // TODO: Implement registerValidateRules() method.
    }

    public function getAttributes(): array
    {
        // TODO: Implement getAttributes() method.
        return [
            "id" => "",
            "mainProcessId" => "开店主流程id",
            "orderNo" => "开店订单号",
            "step" => "门店验收步骤 [ 0:等待指派营运督导 1:指派营运督导 2:督导验收&提交表单 3:省总验收确认 ]",
            "managerName" => "经理名称",
            "managerId" => "经理id",
            "assignTime" => "指派经理时间",
            "formSubmit" => "表单提交内容",
            "formSubmitTime" => "表单提交时间",
            "provinceManagerConfirmTime" => "省总确认时间",
            "createdAt" => "创建时间",
            "createdByUid" => "创建人",
            "updatedAt" => "修改时间",
            "updatedByUid" => "修改人",
        ];
    }

    public function getMessages(): array
    {
        // TODO: Implement getMessages() method.
        return [
            "orderNo.exists" => "当前订单号暂不支持此操作"
        ];
    }

    public function getRules(): array
    {
        // TODO: Implement getRules() method.
        return [
            "id" => "bail|required|int",
            "mainProcessId" => "bail|required|int",
            "orderNo" => "bail|required|string",
            "step" => "bail|required",
            "managerName" => "bail|required|string|min:0|max:60",
            "managerId" => "bail|required|int|min:0|max:9999999",
            "assignTime" => "bail|required|int|date_format:Y-m-d H:i:s",
            "formSubmit" => "bail|required",
            "formSubmitTime" => "bail|required|int|date_format:Y-m-d H:i:s",
            "provinceManagerConfirmTime" => "bail|required|int|date_format:Y-m-d H:i:s",
            "createdAt" => "bail|required|int",
            "createdByUid" => "bail|required|int",
            "updatedAt" => "bail|required|int",
            "updatedByUid" => "bail|required|int",
        ];
    }

    /**
     * @param array $params
     * @return MessageBag|object
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public static function assignManagerValidate(array $params)
    {
        return self::getInstance()->validate(
            ["orderNo", "managerId", "managerName"],
            $params,
            [
                "orderNo" => [
                    "bail",
                    "required",
                    Rule::exists("open_shop_check_accept", "orderNo")
                        ->where("step", MainProcessEnum::SHOP_CHECK_ASSIGN_MANAGER_STAY)
                ]
            ]
        );
    }

    /**
     * @param array $params
     * @return MessageBag|object
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public static function managerConfirmSubmitValidate(array $params)
    {
        return self::getInstance()->validate(
            ["orderNo", "formSubmit"],
            $params,
            [
                "orderNo" => [
                    "bail",
                    "required",
                    Rule::exists("open_shop_check_accept", "orderNo")
                        ->where("step", MainProcessEnum::SHOP_CHECK_ASSIGN_MANAGER)
                ]
            ]
        );
    }

    /**
     * @param array $params
     * @return MessageBag|object
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public static function assignManagerDetailValidate(array $params)
    {
        return self::getInstance()->validate(
            ["orderNo"],
            $params,
            [
                "orderNo" => Rule::exists("open_shop_check_accept", "orderNo")
                    ->where(function($query){
                        $query->where("step", ">",MainProcessEnum::SHOP_CHECK_ASSIGN_MANAGER_STAY);
                    })
            ]
        );
    }

    /**
     * @param array $params
     * @return MessageBag|object
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public static function managerConfirmSubmitDetailValidate(array $params)
    {
        return self::getInstance()->validate(
            ["orderNo"],
            $params,
            [
                "orderNo" => Rule::exists("open_shop_check_accept", "orderNo")
                    ->where(function($query){
                        $query->where("step", ">",MainProcessEnum::SHOP_CHECK_ASSIGN_MANAGER);
                    })
            ]
        );
    }

    /**
     * @param array $params
     * @return MessageBag|object
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public static function updateValidate(array $params)
    {
        return self::getInstance()->validate(
            ["orderNo", "formSubmit"],
            $params,
            [
                "orderNo" => [
                    "bail",
                    "required",
                    Rule::exists("open_shop_check_accept", "orderNo")
                        ->where(function($query){
                            $query->where("step", ">=", MainProcessEnum::SHOP_CHECK_ASSIGN_MANAGER);
                        })
                ]
            ]
        );
    }
}
